#include"Stack.h"

void test1() 
{
	StackQueue st;
	SQInit(&st);
	SQPush(&st, 1);
	SQPush(&st, 2);
	SQPush(&st, 3);
	SQPush(&st, 4);
	while (SQSize(&st))
	{
		printf("%d ", SQTop(&st));
		SQPop(&st);
	}
	printf("\n");

	SQDestroy(&st);
}







typedef struct {
	StackQueue Qpush;
	StackQueue Qpop;
} MyQueue;


MyQueue* myQueueCreate() {
	MyQueue* ptr = (MyQueue*)malloc(sizeof(MyQueue));
	SQInit(&(ptr->Qpush));
	SQInit(&(ptr->Qpop));
	return ptr;
}

void myQueuePush(MyQueue* obj, int x) {
	SQPush(&(obj->Qpush), x);
}

int myQueuePop(MyQueue* obj) {
	int ret = 0;
	if (SQEmpty(&(obj->Qpop)))
	{
		while (!SQEmpty(&(obj->Qpush)))
		{
			SQPush(&(obj->Qpop), SQTop(&(obj->Qpush)));
			SQPop(&obj->Qpush);
		}
	}
	ret = SQTop(&(obj->Qpop));
	SQPop(&(obj->Qpop));
	return ret;
	
}

int myQueuePeek(MyQueue* obj) {
	if (SQEmpty(&(obj->Qpop)))
	{
		while (!SQEmpty(&(obj->Qpush)))
		{
			SQPush(&(obj->Qpop), SQTop(&(obj->Qpush)));
			SQPop(&obj->Qpush);
		}
	}
	return SQTop(&(obj->Qpop));
}

bool myQueueEmpty(MyQueue* obj) {
	return SQEmpty(&(obj->Qpush)) && SQEmpty(&(obj->Qpop));
}

void myQueueFree(MyQueue* obj) {
	SQDestroy(&(obj->Qpop));
	SQDestroy(&(obj->Qpush));
	free(obj);
}



bool isValid(char* s) 
{
	StackQueue st;
	SQInit(&st);
	while (*s)
	{
		if (*s == '(' || *s == '[' || *s == '{')
		{
			SQPush(&st, *s);
		}
		else
		{
			if (SQEmpty(&st))
				return false;
			char ret = 0;
			ret = SQTop(&st);
			if ((*s == ')' && ret != '(' )||(
				*s == ']' && ret != '[' )||(
				*s == '}' && ret != '{'))
			{
				return false;
			}
			if (SQEmpty(&st))
				return false;
			SQPop(&st);
		}
		s++;
	}
	if (SQEmpty(&st))
		return true;
	return false;
}



int main()
{
	test1();
	return 0;
}
